// pages/person/person.js
Page({
  data: {
    checkbox:[1],
    eduDate:['子女入学时间'],
    eduChoice:{choiceHalf:true,choiceWhole:false},
    furtherEduChoice:{yes:false,no:true},
    degreeChoice:{yes:false,no:true},
    babayBox:[1],
    babyBirth:['请选择出生年月'],
    month:"",
    rentBox:[], 
    rentStart:['房租开始时间'], 
    rentEnd:['房租到期时间'], 
    rentType:[], 
    rentChoice:[{cityA:false,cityB:false,cityC:false,noneCity:true}],
    childEduRatio:0.5,
    ruxueDate:"请选择入学时间",
    
     
    elderDate:"请选择老人何时年满六十",
    loanNum:0,
    loanChoice:{half:false,whole:false,noneLoan:true},
    babyChoice:{choiceHalf:true,choiceWhole:false},
    elderChoice:{choice1:false,choice2:false,choice3:false,choice4:false,choice5:false,
      choice6:false,choice7:false,choice8:false,choice9:false,choice10:false,choice0:true},
    elderValue:0,
    degreeValue:"",
    babyCareRatio:0.5,
    // 以下变量3月11日添加
    furtherEduDate:"请输入继续教育申报时间",
    graduateDate:"预计毕业时间",
    loanEndDate:"贷款还完时间",
    loanStartDate:"首次还款时间",
    eduGraduateDate:['终止教育时间'],
    
    calDate:"", 
    totalCount:'0.00',
    fold:false,
    fold1:false,
    fold2:false,
    fold3:false,
    fold4:false,
    fold5:false,
    fold6:false,
    // index: 0,
     // 动态增加房租信息 
     
    componentCount:{
      childEdu:0,
      furEdu:0,
      degree:0,
      loan:0,
      rant:0,
      babyCare:0,
      elder:0
    },
  },

  // 将当前7项专项附加扣除的值加在一起
  calSumResult:function(){
    var com = this.data.componentCount;
    var result = 0;
    for(var key in com){
      result = result + Number(com[key]);
    }
    result = result.toFixed(2)
    this.setData({totalCount:result.toString()});
  },

  toggleFold(e){
    this.setData({fold:!this.data.fold})
  },

  toggleFold1(e){
    this.setData({fold1:!this.data.fold1})
  },

  toggleFold2(e){
    this.setData({fold2:!this.data.fold2})
  },
  toggleFold3(e){
    this.setData({fold3:!this.data.fold3})
  },
  toggleFold4(e){
    this.setData({fold4:!this.data.fold4})
  },
  toggleFold5(e){
    this.setData({fold5:!this.data.fold5})
  },

  toggleFold6(e){
    this.setData({fold6:!this.data.fold6})
  },

  // 比较两个日期大小
  compareDate:function(dateStr1,dateStr2){
    const date1 = new Date(dateStr1);
    const date2 = new Date(dateStr2);
    if (date1 > date2) {
        return 1;
    } else if (date1 < date2) {
        return 2;
    } else {
        return 0;
    }
  },

  //计算dateTime与calDate中间差几个月，跨年度的话就算1月到calDate的月份差
  // @param {String}  dateTime
  // 返回整数 
  calMonthMinus:function(dateTime){ 
    //没填的直接返回0
    if(dateTime.indexOf("-") === -1){
      return 0;
    }
    var calDate = this.data.calDate; 
    var tempDate = dateTime; 
    var tempSplit = tempDate.split("-"); 
    var calSplit = calDate.split("-"); 
    var minus = 0; 
    if(Number(tempSplit[0]) < Number(calSplit[0])){ 
      //年份小于纳税年份，直接返回1月到需要计算月份的月份差 
      minus = Number(calSplit[1]) 
    // 月份大于纳税月份，也就是在未来年份报的，直接忽略
    }else if(Number(tempSplit[0]) > Number(calSplit[0])){ 
      minus = 0;
    }else{
      // 年份相同的情况下,月份大于纳税期，返回0
      if(Number(tempSplit[1]) > Number(calSplit[1])){
        minus = 0;
      }else{
        minus = Number(calSplit[1]) - Number(tempSplit[1]) + 1;
      }
    }
    return minus; 
  }, 

  /* 根据房租月份区间，返回当年可以累计扣除的月份数
  前提，start 恒小于end
  情况1：start <= cal < end
        start如果跨年，则返回cal月份(start == end)
        start不跨年，返回cal - start + 1
  情况2：start < end <= cal
        end跨年，则返回0，
        end不跨年，start跨年，则返回end月份(end == cal)
                  start不跨年，返回end - start + 1
  情况3：cal < start < end
        返回 0

  返回整数类型
   */
  calRentMonth:function(startStr,endStr){
    var end = endStr;
    var start = startStr;
    var cal = this.data.calDate;
    var result = 0;
    //传入其他字符串，直接返回0
    if(end.indexOf("-") === -1 || start.indexOf("-") === -1){
      return 0;
    }
    var startComCal = this.compareDate(cal,start);
    var calComEnd = this.compareDate(cal,end);
    // start <= cal < end
    if(startComCal <= 1 && calComEnd === 2){
       if(start.slice(0,4) !== cal.slice(0,4)){
        result = Number(cal.slice(-2));
       }else{
        result = Number(cal.slice(-2)) - Number(start.slice(-2)) + 1;
       }
       return result;
      // end 小于等于 cal的情况
    }else if(calComEnd <= 1)
    {
      // end跨年
      if(end.slice(0,4) !== cal.slice(0,4)){
        result = 0;
      }
      // end不跨年
      else{
        // start跨年
        if(start.slice(0,4) !== cal.slice(0,4)){
           result = Number(end.slice(-2));
        }
        // start不跨年
        else{
          result = Number(end.slice(-2)) - Number(start.slice(-2)) + 1;
        }
      }
       return result;
    }
    else{
       result = 0;
    }
    return result;
  },

  // 判断当前索引月份是否在当前时间区间内
  isMonthInThatDuration:function(startStr,endStr,monthIdx){
    var cal = this.data.calDate;
    var start = startStr;
    var end = endStr;
    //结束年份小于纳税年份，返回为false
    if(Number(end.slice(0,4)) < Number(cal.slice(0,4))){
       return false;
    }
    // 结束年份等于或大于当前计算年份
    else{
      if(Number(start.slice(0,4)) < Number(cal.slice(0,4))){
        if(Number(end.slice(-2)) > monthIdx){
           return true;
        }
      }else if(Number(start.slice(0,4)) === Number(cal.slice(0,4))){
        if(Number(end.slice(-2)) >= monthIdx && Number(start.slice(-2)) <= monthIdx){
          return true;
       }
      }else;
    }
    return false;
  },

  // 计算房租累计专项附加扣除
calRentKouchu:function(){
  var rent = this.data.rentType;
  var start = this.data.rentStart;
  var end = this.data.rentEnd;
  var rentBox = this.data.rentBox;
  var cal = this.data.calDate;
  var result = 0;
  var monthLength = Number(cal.slice(-2));
  // 已知end恒大于start，start恒小于等于caldate
  for(var i = 1;i <= monthLength;i++){
    // console.log("i的取值:"+i)
   for(var j = 0;j < rentBox.length;j++){
    // console.log("判断取值"+this.isMonthInThatDuration(start[j],end[j],i))
     if(this.isMonthInThatDuration(start[j],end[j],i)){
       result = result + rent[j];
       break;
     }else{
       result = result + 0;
     }    
   }
  }
  this.setData({"componentCount.rant":result});
},

  insertEdu(e){
    var cb = this.data.checkbox;
    var start = this.data.eduDate;
    var end = this.data.eduGraduateDate;
    cb.push(this.data.checkbox.length+1);
    start.push('请选择入学时间');
    end.push('终止教育时间')
    this.setData({checkbox: cb,eduDate:start,eduGraduateDate:end});
  },

  delEdu(e){
    var cb = this.data.checkbox;
    var start = this.data.eduDate;
    var end = this.data.eduGraduateDate;
    cb.pop();
    start.pop();
    end.pop();
    this.setData({checkbox: cb,eduDate:start,eduGraduateDate:end});
  },

  insertBaby(e){
    var bb = this.data.babayBox;
    var birth = this.data.babyBirth;
    bb.push(bb.length+1);
    birth.push('请选择出生年月');
    this.setData({babayBox: bb,babyBirth:birth});
  },

  delBaby(e){
    var bb = this.data.babayBox;
    var birth = this.data.babyBirth;
    bb.pop();
    birth.pop();
    this.setData({babayBox: bb,babyBirth:birth});
  },

  insertRent(e){ 
    var rb = this.data.rentBox; 
    var rs = this.data.rentStart; 
    var re = this.data.rentEnd; 
    var type = this.data.rentType; 
    var rentChoice = this.data.rentChoice;
    rb.push(rb.length+1); 
    rs.push('房租开始时间'); 
    re.push('房租到期时间'); 
    rentChoice.push({cityA:false,cityB:false,cityC:false,noneCity:true})
    type.push(0); 
    this.setData({rentBox:rb,rentStart:rs,rentEnd:re,rentType:type,rentChoice:rentChoice}); 
  }, 
 
  delRent(e){ 
    var rb = this.data.rentBox; 
    var rs = this.data.rentStart; 
    var re = this.data.rentEnd; 
    var type = this.data.rentType; 
    var rentChoice = this.data.rentChoice;
    rb.pop(); 
    rs.pop(); 
    re.pop(); 
    rentChoice.pop();
    type.pop();
    this.setData({rentBox:rb,rentStart:rs,rentEnd:re,rentChoice:rentChoice,rentType:type});
    // this.calRentKouchu();
  }, 
  
  //单选框确定扣除标准
  elderChange(e){
    var val = e.detail.value;
    val = Number(val);
    var date = this.data.elderDate;
    var elderChoice = this.data.elderChoice;
    this.setData({elderValue:val});
    if(date.indexOf("-") === -1 && val !== 0){
      wx.showToast({
        title: '请输入老人何时年满六十！',
      });
      elderChoice.choice0 = true;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
      this.setData({elderChoice:elderChoice});
      return;
    }
    if(val === 3000){
      elderChoice.choice0 = false;
      elderChoice.choice1 = true;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }else if(val === 1500){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = true;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;  
      elderChoice.choice10 = false;
    }else if(val === 1000){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = true;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }else if(val === 750){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = true;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }else if(val === 600){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = true;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }else if(val === 500){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = true;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }else if(val === 428.57){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = true;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }
    else if(val === 375){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = true;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }
    else if(val === 333.33){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = true;
      elderChoice.choice10 = false;
    }
    else if(val === 300){
      elderChoice.choice0 = false;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = true;
    }else{
      elderChoice.choice0 = true;
      elderChoice.choice1 = false;
      elderChoice.choice2 = false;
      elderChoice.choice3 = false;
      elderChoice.choice4 = false;
      elderChoice.choice5 = false;
      elderChoice.choice6 = false;
      elderChoice.choice7 = false;
      elderChoice.choice8 = false;
      elderChoice.choice9 = false;
      elderChoice.choice10 = false;
    }
    this.setData({elderChoice:elderChoice});
  },

  bindEduDateChange(e){
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引
    var val = e.detail.value;//获取输入的索引
    var oldVal = this.data.eduDate;
    let that = this;
    oldVal[nowIdx]=val;//修改对应索引值的内容
    that.setData({
      eduDate: oldVal
    });
  },

  bindEduGraduateDateChange(e){
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引
    var val = e.detail.value;
    var end = this.data.eduGraduateDate;
    var start = this.data.eduDate;
    if(start[nowIdx].indexOf("-") === -1){
      wx.showToast({
        title: '请先输入子女入学时间！',
        icon:'none'
      });
      return;
    }
    let that = this;
    end[nowIdx] = val;
    that.setData({
      eduGraduateDate: end
    });
  },
  

  bindFurtherEduDateChange(e){
    var val = e.detail.value;
    let that = this;
    that.setData({
      furtherEduDate: val
    });
  },

  

  bindRuxueDateChange(e){
    var val = e.detail.value;
    let that = this;
    that.setData({
      ruxueDate: val
    });
  },

  bindGraduateDateChange(e){
    var val = e.detail.value;
    var start = this.data.ruxueDate;
    if(start.indexOf("-") === -1){
      wx.showToast({
        title: '请先输入入学时间！',
        icon:'none'
      });
      return;
    }
    let that = this;
    that.setData({
      graduateDate: val
    });
  },

  bindLoanStartDateChange(e){
    var val = e.detail.value;
    let that = this;
    that.setData({
      loanStartDate: val
    });
  },

  bindLoanEndDateChange(e){
    var val = e.detail.value;
    let that = this;
    var start = this.data.loanStartDate;
    if(start.indexOf("-") === -1){
      wx.showToast({
        title: '请先输入首次还款时间！',
        icon:'none'
      });
      return;
    }
    that.setData({
      loanEndDate: val
    });
  },

  // bindRentDateChange(e){
  //   var val = e.detail.value;
  //   let that = this;
  //   that.setData({
  //     rentDate: val
  //   });
  // },

  bindElderDateChange(e){
    var val = e.detail.value;
    let that = this;
    that.setData({
      elderDate: val
    });
  },

  bindRentStartChange(e){ 
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引 
    var val = e.detail.value;//获取输入的索引 
    let that = this; 
    var rentStart = that.data.rentStart; 
    rentStart[nowIdx] = val; 
    that.setData({rentStart:rentStart}); 
  }, 
 
  bindRentEndChange(e){ 
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引 
    var val = e.detail.value;//获取输入的索引 
    var start = this.data.rentStart; 
    // 不选择开始时间，结束时间也不能选！ 
    if(start[nowIdx].indexOf("-") === -1){ 
      wx.showToast({ 
        title: '请选择房租开始时间！', 
        icon:'none' 
      }); 
      return; 
    } 
    var end = this.data.rentEnd; 
    end[nowIdx] = val; 
    this.setData({rentEnd:end}); 
  }, 

  bindBabyBirthChange(e){
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引 
    var val = e.detail.value;//获取输入的索引
    var birth = this.data.babyBirth;
    birth[nowIdx] = val;
    this.setData({babyBirth:birth});
    // console.log(this.data.componentCount);
  },
 
  
// 计算累计子女教育扣除金额
calChildEdu:function(){
  var result = 0,minus = 0;
  var ruxuedate = this.data.eduDate;
  var graduate = this.data.eduGraduateDate;
  var cal = this.data.calDate;
  // console.log(ruxuedate);
  for(var i = 0; i < ruxuedate.length;i++){
    if(ruxuedate[i].indexOf("-") === -1 || graduate[i].indexOf("-") === -1){
      continue;
    }
    // 当前子女入学时间大于纳税期，就不算了
    if(this.compareDate(ruxuedate[i],cal) === 1){
      continue;
    }
    minus = this.calRentMonth(ruxuedate[i],graduate[i]);
    console.log("minusMonthforchildEdu:"+minus);
    result = result + minus * 2000;
  }
  var percent = this.data.childEduRatio;
  result = (result * percent).toFixed(2);
  console.log("result:"+result);
  this.setData({"componentCount.childEdu":result});
  console.log(this.data.componentCount)
},

calLoan:function(){
  var loanStart = this.data.loanStartDate;
  var loanEnd = this.data.loanEndDate;
  // 首套贷的时间区间和租房时间区间是一样的
  var minus = this.calRentMonth(loanStart,loanEnd)
  var loanNum = this.data.loanNum;
  var loan = minus * loanNum;
  loan = loan.toFixed(2);
  this.setData({"componentCount.loan":loan});
},

//计算学历教育的专项附加扣除
calDegree:function(){
  var ruxueDate = this.data.ruxueDate;
  var graduate = this.data.graduateDate;
  var degreeEdu = this.data.degreeValue;
  var minus = this.calRentMonth(ruxueDate,graduate);
  var result = minus * degreeEdu;
  result = result.toFixed(2);
  let that = this;
  that.setData({"componentCount.degree":result});
},

// 计算扣除标准
calElder:function(){
  var elderDate = this.data.elderDate;
  var minus = this.calMonthMinus(elderDate);
  var ratio = this.data.elderValue;
  var result = minus * ratio;
  this.setData({'componentCount.elder':result});
},

  
  // 计算婴幼儿照护部分的专项附加扣除
  calBabyCare:function(){
    var birth = this.data.babyBirth;
    var monthMinus = 0,result = 0;
    for(var i = 0;i < birth.length;i++){
      monthMinus = this.calMonthMinus(birth[i]);
      result = result + monthMinus * 2000;
    }
    var ratio = this.data.babyCareRatio;
    result = (result * ratio).toFixed(2);
    this.setData({"componentCount.babyCare":result});
  },

  //修改子女教育扣除主体
  radioEducationChange(e){
    // 记录用户的选择记录
     var newRatio = e.detail.value;
     var edu = this.data.eduChoice;
     if(newRatio === '1'){
       edu.choiceWhole = true;
       edu.choiceHalf = false;
     }else{
       edu.choiceHalf = true;
       edu.choiceWhole = false;
     }
     this.setData({eduChoice:edu});
     newRatio = Number.parseFloat(newRatio);
    //  var childEduFee = this.data.childNum * 2000 * newRatio;
     this.setData({childEduRatio:newRatio});
  },

  //继续教育专项附加扣除计算,只有2项
  furtherEducationChange(e){
    var furtherEduChoice = this.data.furtherEduChoice;
    var furEdu = Number(e.detail.value);
    var furDate = this.data.furtherEduDate;
    if(furEdu === 3600 && furDate.indexOf("-") === -1){
      wx.showToast({
        title: '请选择本年度申报继续教育的时间',
        icon:'none'
      });
      furtherEduChoice.yes = false;
      furtherEduChoice.no = true;
      this.setData({furtherEduChoice:furtherEduChoice});
      return; 
    }
    if(furEdu === 3600){
      furtherEduChoice.yes = true;
      furtherEduChoice.no = false;
    }else{
      furtherEduChoice.yes = false;
      furtherEduChoice.no = true;
    }
    console.log(furEdu);
    this.setData({"componentCount.furEdu":furEdu});
    this.setData({furtherEduChoice:furtherEduChoice});
    console.log(this.data.componentCount);
  },

  degreeEducationChange(e){
    var degreeEdu = Number(e.detail.value);
    var ruxueDate = this.data.ruxueDate;
    var graduateDate = this.data.graduateDate;
    var degreeChoice = this.data.degreeChoice;
    // 申报了学历教育但是不填写入学时间会有提示
    if(degreeEdu === 400 && (ruxueDate.indexOf("-") === -1 || graduateDate.indexOf("-") === -1)){
      wx.showToast({
        title: '请输入入学与毕业时间！\r\n否则学历教育填报无效',
        icon:'none'
      });
      degreeChoice.yes=false;
      degreeChoice.no=true;
      this.setData({degreeChoice:degreeChoice});
      return;
    }
    if(degreeEdu === 400){
      degreeChoice.yes=true;
      degreeChoice.no=false;
      this.setData({degreeChoice:degreeChoice});
    }else{
      degreeChoice.yes=false;
      degreeChoice.no=true;
      this.setData({degreeChoice:degreeChoice});
    }
    this.setData({degreeValue:degreeEdu});
  },

  //首套房房贷处理
  loanChange(e){
    var loanStartDate = this.data.loanStartDate;
    var loanEndDate = this.data.loanEndDate;
    var loanChoice = this.data.loanChoice;
    var loanNum = Number(e.detail.value);
    this.setData({loanNum:loanNum});
    // 填写贷款信息但是没有填写时间
    if(loanNum !== 0 && (loanStartDate.indexOf("-") === -1 || loanEndDate.indexOf("-") === 1)){
      wx.showToast({
        title: '请输入首套房相关时间信息！\r\n否则填报信息无效',
        icon:'none'
      });
      loanChoice.half = false;
      loanChoice.whole = false;
      loanChoice.noneLoan = true;
      this.setData({loanChoice:loanChoice});
      return;
    }
    if(loanNum === 500){
      loanChoice.half = true;
      loanChoice.whole = false;
      loanChoice.noneLoan = false;
    }else if(loanNum === 1000){
      loanChoice.half = false;
      loanChoice.whole = true;
      loanChoice.noneLoan = false;
    }else{
      loanChoice.half = false;
      loanChoice.whole = false;
      loanChoice.noneLoan = true;
    }
    this.setData({loanChoice:loanChoice});
  },

  //住房租金城市处理
  onRentChange(e){
    var nowIdx = e.currentTarget.dataset.idx;//获取当前索引
    var start = this.data.rentStart;
    var end = this.data.rentEnd;
    var loanNum = Number(e.detail.value);
    var rent = this.data.rentType;
    var rentChoice = this.data.rentChoice;
    rent[nowIdx] = loanNum;
    // console.log("start:"+start[nowIdx]+" end:"+end[nowIdx]);
    // console.log("start判断结果"+start[nowIdx].includes("-"))
    if(start[nowIdx].includes("-") === false || end[nowIdx].includes("-") === false){
      wx.showToast({
        title: '请完整填写租房时间！',
        icon:'none'
      });
      rentChoice[nowIdx].noneCity = true;
      rentChoice[nowIdx].cityA = false;
      rentChoice[nowIdx].cityB = false;
      rentChoice[nowIdx].cityC = false;
      this.setData({rentChoice:rentChoice})
      return;
    }
    if(loanNum === 0){
      rentChoice[nowIdx].noneCity = true;
      rentChoice[nowIdx].cityA = false;
      rentChoice[nowIdx].cityB = false;
      rentChoice[nowIdx].cityC = false;
    }else if (loanNum === 800){
      rentChoice[nowIdx].noneCity = false;
      rentChoice[nowIdx].cityA = false;
      rentChoice[nowIdx].cityB = false;
      rentChoice[nowIdx].cityC = true;
    }else if (loanNum === 1100){
      rentChoice[nowIdx].noneCity = false;
      rentChoice[nowIdx].cityA = false;
      rentChoice[nowIdx].cityB = true;
      rentChoice[nowIdx].cityC = false;
    }else{
      rentChoice[nowIdx].noneCity = false;
      rentChoice[nowIdx].cityA = true;
      rentChoice[nowIdx].cityB = false;
      rentChoice[nowIdx].cityC = false;
    }
    this.setData({rentChoice:rentChoice})
    this.setData({rentType:rent});
  },

  //选择婴幼儿扣除主体
  ratioBabyCare(e){
     var newRatio = e.detail.value;
     var babyChoice = this.data.babyChoice;
     newRatio = Number.parseFloat(newRatio);
     if(newRatio === 0.5){
      babyChoice.choiceHalf = true;
      babyChoice.choiceWhole = false;
     }else{
      babyChoice.choiceHalf = false;
      babyChoice.choiceWhole = true;
     }
     this.setData({babyCareRatio:newRatio,babyChoice:babyChoice});
  },

  formSubmit: function(event) {
    var that = this
    that.calChildEdu();
    that.calDegree();
    that.calLoan();
    that.calRentKouchu();
    that.calBabyCare();
    that.calElder();
    that.calSumResult();
    
    // app.globalData.eduDate = that.data.eduDate;
    // app.globalData.eduGraduateDate = that.data.eduGraduateDate;
    // app.globalData.childEduRatio = that.data.childEduRatio;

    // app.globalData.furtherEduChoice = that.data.furtherEduChoice;
    // app.globalData.furtherEduDate = that.data.furtherEduDate;

    // app.globalData.degreeValue = that.data.degreeValue;
    // app.globalData.graduateDate = that.data.graduateDate;
    // app.globalData.degreeRuXueDate = that.data.ruxueDate;

    // app.globalData.babyBirth = that.data.babyBirth;
    // app.globalData.babyCareRatio = that.data.babyCareRatio;

    // app.globalData.rentStart = that.data.rentStart;
    // app.globalData.rentEnd = that.data.rentEnd;
    // app.globalData.rentType = that.data.rentType;

    // app.globalData.loanStartDate = that.data.loanStartDate;
    // app.globalData.loanEndDate = that.data.loanEndDate;
    // app.globalData.loanNum = that.data.loanNum;

    // app.globalData.elderDate = that.data.elderDate;
    // app.globalData.elderValue = that.data.elderValue;

    //子女教育
    const eduBox  = JSON.stringify(that.data.checkbox)
    const eduDate   = JSON.stringify(that.data.eduDate)
    const eduChoice = JSON.stringify(that.data.eduChoice)
    const childEduRatio = JSON.stringify(that.data.childEduRatio)
    //继续教育
    const furtherEduChoice  = JSON.stringify(that.data.furtherEduChoice)
    //学历教育
    const degreeRuXueDate     = JSON.stringify(that.data.ruxueDate)
    const degreeValue   = JSON.stringify(that.data.degreeValue)
    const degreeChoice  = JSON.stringify(that.data.degreeChoice)
    //婴幼儿
    const babayBox      = JSON.stringify(that.data.babayBox)
    const babyBirth     = JSON.stringify(that.data.babyBirth)
    const babyChoice    = JSON.stringify(that.data.babyChoice)
    const babyCareRatio = JSON.stringify(that.data.babyCareRatio)
    //租房
    const rentBox       = JSON.stringify(that.data.rentBox)
    const rentStart     = JSON.stringify(that.data.rentStart)
    const rentEnd       = JSON.stringify(that.data.rentEnd)
    const rentType      = JSON.stringify(that.data.rentType)
    const rentChoice    = JSON.stringify(that.data.rentChoice)
    //首套房贷款
    const loanStartDate      = JSON.stringify(that.data.loanStartDate)
    const loanNum       = JSON.stringify(that.data.loanNum)
    const loanChoice    = JSON.stringify(that.data.loanChoice)
    //赡养老人
    const elderDate     = JSON.stringify(that.data.elderDate)
    const elderChoice   = JSON.stringify(that.data.elderChoice)
    const elderValue    = JSON.stringify(that.data.elderValue)
    
    //3月11日新增变量
    const furtherEduDate = JSON.stringify(that.data.furtherEduDate);
    const graduateDate = JSON.stringify(that.data.graduateDate);
    const loanEndDate = JSON.stringify(that.data.loanEndDate);
    const eduGraduateDate  = JSON.stringify(that.data.eduGraduateDate);
    const componentCount = JSON.stringify(that.data.componentCount);
    
    try {
      wx.setStorageSync('eduBox',  eduBox);
      wx.setStorageSync('eduDate',  eduDate);
      wx.setStorageSync('eduChoice',  eduChoice);
      wx.setStorageSync('childEduRatio',  childEduRatio);
      wx.setStorageSync('furtherEduChoice',  furtherEduChoice);
      wx.setStorageSync('degreeRuXueDate',  degreeRuXueDate);
      wx.setStorageSync('degreeValue',  degreeValue);
      wx.setStorageSync('degreeChoice',  degreeChoice);
      wx.setStorageSync('babayBox',  babayBox);
      wx.setStorageSync('babyBirth',  babyBirth);
      wx.setStorageSync('babyChoice',  babyChoice);
      wx.setStorageSync('babyCareRatio',  babyCareRatio);
      wx.setStorageSync('rentBox',  rentBox);
      wx.setStorageSync('rentStart',  rentStart);
      wx.setStorageSync('rentEnd',  rentEnd);
      wx.setStorageSync('rentType',  rentType);
      wx.setStorageSync('rentChoice',  rentChoice);
      wx.setStorageSync('loanStartDate',  loanStartDate);
      wx.setStorageSync('loanNum',  loanNum);
      wx.setStorageSync('loanChoice',  loanChoice);
      wx.setStorageSync('elderDate',  elderDate);
      wx.setStorageSync('elderChoice',  elderChoice);
      wx.setStorageSync('elderValue',  elderValue);
      wx.setStorageSync('furtherEduDate',  furtherEduDate);
      wx.setStorageSync('graduateDate',  graduateDate);
      wx.setStorageSync('loanEndDate',  loanEndDate);
      wx.setStorageSync('eduGraduateDate',  eduGraduateDate);
      wx.setStorageSync('componentCount', componentCount);
    } catch (e) { 
      console.log(e)
    }
    
    /**
     * const furtherEduDate = JSON.stringify(this.data.furtherEduDate);
      const graduateDate = JSON.stringify(this.data.graduateDate)
     const loanEndDate = JSON.stringify(this.data.loanEndDate)
     */
    let pages = getCurrentPages();//当前页面
    let prevPage = pages[ pages.length - 2 ];
    //var value = Number.parseFloat(that.data.totalCount);
    //app.globalData.zxPerson = that.data.totalCount;
    prevPage.setData({
      person:that.data.totalCount
    });
    wx.navigateBack({
      delta: 1  // 返回上一级页面。
    });
  },

  formReset:function(){
    //console.log('已清空填写内容')
    this.setData({
    totalCount:'0.00',
    checkbox:[],
    eduDate:[],
    babayBox:[],
    babyBirth:[],
    index1:[],
    month:"",
    rentBox:[], 
    rentStart:['房租开始时间'], 
    rentEnd:['房租到期时间'], 
    rentType:[], 
    childEduRatio:0.5,
    ruxueDate:"请选择入学时间",
    elderDate:"请选择老人何时年满六十",
    elderValue:0,
    babyCareRatio:0.5,
    furtherEduDate:"请输入继续教育申报时间",
    graduateDate:"预计毕业时间",
    loanEndDate:"贷款还完时间",
    loanStartDate:"首次还款时间",
    eduGraduateDate:[]
    });
},
  
  onLoad(options) {
    wx.showShareMenu({
      withShareTicket:true,
      menus:["shareAppMessage",'shareTimeline']});
    const mon = options.calDate; 
    this.setData({calDate:mon}); 
    // console.log(mon);

    //根据用户输入自动算出婴幼儿最早的出生年月 
    var babyBond = mon.split("-"); 
    var year = babyBond[0]; 
    var year1 = babyBond[0]; 
    year = Number(year) - 3; 
    year = year + "-" + babyBond[1]; 
    // console.log(year); 
    this.setData({babyBond:year,month:year1}); 

    let that = this;
    try {
      var value = wx.getStorageSync('eduBox');
      if(value){
        that.setData({checkbox:JSON.parse(value)});
      }
      value = wx.getStorageSync('eduDate');
      if(value){
        that.setData({eduDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('eduChoice');
      if(value){
      that.setData({eduChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('childEduRatio' );
      if(value){
      that.setData({childEduRatio:JSON.parse(value)});
      }
      value = wx.getStorageSync('furtherEduChoice' );
      if(value){
      that.setData({furtherEduChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('degreeRuXueDate' );
      if(value){
      that.setData({ruxueDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('degreeValue' );
      if(value){
      that.setData({degreeValue:JSON.parse(value)});
      }
      value = wx.getStorageSync('degreeChoice' );
      if(value){
      that.setData({degreeChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('babayBox' );
      if(value){
      that.setData({babayBox:JSON.parse(value)});
      }
      value = wx.getStorageSync('babyBirth' );
      if(value){
      that.setData({babyBirth:JSON.parse(value)});
      }
      value = wx.getStorageSync('babyChoice' );
      if(value){
      that.setData({babyChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('babyCareRatio' );
      if(value){
      that.setData({babyCareRatio:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentBox');
      if(value){
      that.setData({rentBox:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentStart' );
      if(value){
      that.setData({rentStart:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentEnd' );
      if(value){
      that.setData({rentEnd:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentType' );
      if(value){
      that.setData({rentType:JSON.parse(value)});
      }
      value = wx.getStorageSync('rentChoice' );
      if(value){
      that.setData({rentChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanStartDate' );
      if(value){
      that.setData({loanStartDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanNum' );
      if(value){
      that.setData({loanNum:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanChoice');
      if(value){
      that.setData({loanChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('elderDate' );
      if(value){
      that.setData({elderDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('elderChoice' );
      if(value){
      that.setData({elderChoice:JSON.parse(value)});
      }
      value = wx.getStorageSync('elderValue');
      if(value){
      that.setData({elderValue:JSON.parse(value)});
      }
      value = wx.getStorageSync('furtherEduDate');
      if(value){
      that.setData({furtherEduDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('graduateDate' );
      if(value){
      that.setData({graduateDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('loanEndDate' );
      if(value){
      that.setData({loanEndDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('eduGraduateDate');
      if(value){
      that.setData({eduGraduateDate:JSON.parse(value)});
      }
      value = wx.getStorageSync('componentCount');
      if(value){
        that.setData({componentCount:JSON.parse(value)});
      }
    } catch (e) {
      // Do something when catch error
      console.log(e)
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '答哥算税计算器',
      path: '/pages/index/index'
    }
  }
})